// https://leetcode.cn/problems/product-of-array-except-self/description/

/**
 * @param {number[]} nums
 * @return {number[]}
 */
var productExceptSelf = function (nums) {
  let n = nums.length;
  let suf = 1;
  let pre = 1;
  let res = [];
  for (let i = 0; i < n; i++) {
    res[i] = pre;
    pre *= nums[i];
  }
  for (let j = n - 1; j >= 0; j--) {
    res[j] *= suf;
    suf *= nums[j];
  }
  return res;
};

let nums = [-1, 1, 0, -3, 3];
console.time("time1");
console.log(productExceptSelf(nums));
console.timeEnd("time1");
